import java.util.ArrayList;

public class BowlingGame
{
	private ArrayList<Frame> frames;
	private Frame current;
	private int index = 0;
	public BowlingGame()
	{
		frames = new ArrayList<Frame>();
		frames.add(new Frame());
		for (int x = 1; x <= 8; x++)
		{
			frames.add(new Frame());
			frames.get(x - 1).setNext(frames.get(x));
		}
		frames.add(new TenthFrame());
		frames.get(8).setNext(frames.get(9));
	}
	public void bowl(int pins)
	{
		current = frames.get(index);
		current.bowl(pins);
		if (current.getAttempts() == 0 && index < 11)
		{
			index++;
		}
	}
	public ArrayList<Frame> getFrames()
	{
		return this.frames;
	}
	public void setFrames(ArrayList<Frame> frames)
	{
		this.frames = frames;
	}
	public Frame getCurrent()
	{
		return this.current;
	}
	public void setCurrent(Frame current)
	{
		this.current = current;
	}
	public int getIndex()
	{
		return this.index;
	}
	public void setIndex(int index)
	{
		this.index = index;
	}
	public int getScore()
	{
		int score = 0;
		Frame curr;
		for (int x = 0; x < frames.size(); x++)
		{
			curr = frames.get(x);
			try
			{
				score += curr.getScore();
			}
			catch (IndexOutOfBoundsException e) {}
		}
		return score;
	}
}
